package person.bing.fbcloud.leetcode;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 没做出来
 *
 * @author: mengfanbing
 * @date: 2020/11/17 10:13
 */
public class Q1030 {
    public static void main(String[] args) {
        int[][] ints = allCellsDistOrder(4 ,9, 3, 8);
        System.out.println(Arrays.toString(ints));
    }

    public static int[][] allCellsDistOrder(int R, int C, int r0, int c0) {
        int num = R*C;
        int[][] result = new int[num][2];
        List<String> temp = new ArrayList<>();
        for (int i=0;i<R;i++){
            for (int j=0;j<C;j++){
                int a = i-r0;
                a = a >= 0 ? a : -a;
                int b = j-c0;
                b = b >= 0 ? b : -b;
                int sum = a+b;
                temp.add(sum + "-" + i + "-"+ j);
            }
        }
        List<Integer> lengList = temp.stream().map(s -> {
            return Integer.valueOf(s.split("-")[0]);
        }).distinct().sorted().collect(Collectors.toList());

        lengList.stream().forEach(s -> {
            String head = s + "-";

        });
        temp = temp.stream().sorted().collect(Collectors.toList());


        for (int i=0;i<num;i++){
            String str = temp.get(i);
            String[] split = str.split("-");
            result[i][0] = Integer.valueOf(split[1]);
            result[i][1] = Integer.valueOf(split[2]);
            System.out.println(str);
        }
        return result;
    }
}
